//
//  CompanyInfoInPutCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/8/31.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "CompanyInfoInPutCell.h"

@interface CompanyInfoInPutCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *xingLab;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UITextField *textField;
@property (nonatomic, strong) UILabel *lineLab;

@end

@implementation CompanyInfoInPutCell

+ (instancetype)CompanyInfoInPutCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"CompanyInfoInPutCell";
    CompanyInfoInPutCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[CompanyInfoInPutCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, 60)];
        self.bgView.backgroundColor = HexColor(0xffffff);
        [self.contentView addSubview:self.bgView];
        
        self.lineLab = [[UILabel alloc] initWithFrame:CGRectMake(10, self.bgView.nim_height - 1, self.bgView.nim_width - 20, 1)];
        self.lineLab.backgroundColor = Color_backgroundColor;
        [self.bgView addSubview:self.lineLab];
        
        self.xingLab = [UILabel new];
        self.xingLab.text = @"*";
        self.xingLab.font = [UIFont systemFontOfSize:14];
        [self.xingLab sizeToFit];
        self.xingLab.nim_left = 10;
        self.xingLab.nim_top = 20;
        self.xingLab.textColor = HexColor(0xF35959);
        [self.bgView addSubview:self.xingLab];
        
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(self.xingLab.nim_right, 22.5, 120, 15)];
        self.titleLab.font = [UIFont systemFontOfSize:14];
        self.titleLab.textColor = HexColor(0x2B2C44);
        [self.bgView addSubview:self.titleLab];
        
        self.textField = [[UITextField alloc] initWithFrame:CGRectMake(self.titleLab.nim_right, 10, self.bgView.nim_width - 10 - self.titleLab.nim_right, 40)];
        self.textField.font = [UIFont systemFontOfSize:15];
        self.textField.textColor = HexColor(0x000000);
        self.textField.textAlignment = NSTextAlignmentRight;
        [self.textField addTarget:self action:@selector(fieldTextChanged:) forControlEvents:UIControlEventEditingChanged];
        [self.bgView addSubview:self.textField];
        
        self.height = self.bgView.nim_bottom;
    }
    return self;
}

- (void)fieldTextChanged:(UITextField *)field {
    if (self.cellBlock) {
        self.cellBlock(field.text);
    }
}

-(void)setIsCanNoEdit:(BOOL)isCanNoEdit {
    _isCanNoEdit = isCanNoEdit;
    self.textField.userInteractionEnabled = !isCanNoEdit;
}

-(void)setIsMust:(BOOL)isMust {
    _isMust = isMust;
    self.xingLab.hidden = !isMust;
}

-(void)setTitleText:(NSString *)titleText {
    _titleText = titleText;
    self.titleLab.text = titleText;
}

-(void)setContentText:(NSString *)contentText {
    _contentText = contentText;
    self.textField.text = contentText;
}

-(void)setShowLine:(BOOL)showLine {
    _showLine = showLine;
    self.lineLab.hidden = !showLine;
}

-(void)setCanClick:(BOOL)canClick {
    _canClick = canClick;
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 18, 18)];
    imgView.image = [UIImage imageNamed:@"icon_lower_person_info"];
    if (canClick) {
        self.textField.placeholder = @"请选择";
        self.textField.rightView = imgView;
        self.textField.rightViewMode = UITextFieldViewModeAlways;
    }else {
        self.textField.placeholder = @"请输入";
        self.textField.rightView = [UIView new];
        self.textField.rightViewMode = UITextFieldViewModeAlways;
    }
    self.textField.userInteractionEnabled = !canClick;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
